const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {

  },

  onLoad: function() {
    var that = this;
    that.setTabBar();
    var userInfo = wx.getStorageSync('userInfo');
    that.setData({
      user: userInfo.wxInfo
    });
  },
  setTop: function (setting) {
    var that = this;
    var backgroundColor = setting.pro.backgroundColor != undefined ? setting.pro.backgroundColor : '#000000';
    var frontColor = setting.pro.frontColor != undefined ? setting.pro.frontColor : '#ffffff';
    var currentPage = getCurrentPages();
    var page = currentPage[0].route;
    wx.setNavigationBarColor({
      frontColor: frontColor,
      backgroundColor: backgroundColor
    });
    var tarBar = that.data.blist;
    for (let key in tarBar) {
      if (tarBar[key].link == page) {
        wx.setNavigationBarTitle({
          'title': tarBar[key].title
        });
        break;
      }
    }
    that.setData({
      currentPage: page
    });
  },
  // 设置底部导航
  setTabBar: function () {
    var that = this;
    var cache = wx.getStorageSync("barlist");
    var setting = {};
    if (cache) {
      setting = cache;
      that.setData({
        blist: cache.menu,
        pro: cache.pro
      });
      that.setTop(setting);
    } else {
      http.get('quickmenu', {}).then(function (res) {
        setting = res;
        console.log(setting);
        if (res != {}) {
          that.setTop(setting);
          wx.setStorageSync('barlist', res);
          that.setData({
            blist: res.menu,
            pro: res.pro
          });
        } else {
          that.setData({
            blist: [],
            pro: []
          });
        }
      });
    }
  },
  goToUrl: function (options) {
    var url = options.target.dataset.url;
    wx.navigateTo({
      url: url,
    })
  }
})